import api from "../../../api/index";
export default {
  state:{
    loading:true,
    recharge_day:0,
    yesterday_recharge_day:0,
    monthSum:0,
    logon_num:0,
    yesterday_logon_num:0,
    registerCount:0,
    yesterday_regist_peo:0,
    recharge_peo:0,
    yesterday_recharge_peo:0,
    realtime_arppu_inc:0,
    tableData:[]
  },
  getters:{
    realtime_recharge_day_inc: state=>{
      return state.yesterday_recharge_day?((state.recharge_day-state.yesterday_recharge_day)*100/state.yesterday_recharge_day).toFixed(2):0;
    },
    realtime_logon_num_inc: state=>{
      return state.yesterday_logon_num?((state.logon_num-state.yesterday_logon_num)*100/state.yesterday_logon_num).toFixed(2):0;
    },
    realtime_regist_peo_inc: state=>{
      return state.yesterday_regist_peo?((state.registerCount-state.yesterday_regist_peo)*100/state.yesterday_regist_peo).toFixed(2):0;
    },
    realtime_recharge_peo_inc: state=>{
      return state.yesterday_recharge_peo?((state.recharge_peo-state.yesterday_recharge_peo)*100/state.yesterday_recharge_peo).toFixed(2):0;
    },
    realtime_arppu:state=>{
      let arppu = state.recharge_peo?(state.recharge_day/state.recharge_peo).toFixed(2):0;
      let yes_ = state.yesterday_recharge_peo?state.yesterday_recharge_day/state.yesterday_recharge_peo:0;
      state.realtime_arppu_inc = yes_?((arppu-yes_)/yes_).toFixed(2):0;
      return arppu;
    },
    realtime_echartsData:state=>{
      let linedata = [];
      state.tableData.forEach((currentValue)=>{
        let s2={value:[]};
        s2.value.push(currentValue.count_date);
        s2.value.push(currentValue.recharge_day);
        linedata.push(s2);
      });
      return [linedata];
    }
  },
  mutations:{
    realtime_tableData(state,data){
      state.tableData=data;
    },
    realtime_showLoading(state){
      state.loading = true;
    },
    realtime_endLoading(state){
      state.loading = false;
    },
    realtime_cardData(state,data){
      state.recharge_day = data.recharge_day||0;
      //state.yesterday_recharge_day = data.yesterday_recharge_day||0;
      state.monthSum = data.monthSum||0;
      state.logon_num = data.logon_num||0;
      state.registerCount = data.registerCount || 0;
      state.yesterday_logon_num = data.yesterday_login_peo||0;
      state.yesterday_regist_peo = data.yesterday_regist_peo||0;
      state.yesterday_recharge_peo = data.yesterday_recharge_peo||0;
      state.yesterday_recharge_day = data.yesterday_recharge_day||0;
      state.recharge_peo = data.recharge_peo ||0;
    }
  },
  actions:{
    realtime_tableData(context,{set,...para}){
      context.commit('realtime_showLoading');
      api.getArpuList(para,set)
        .then((response) =>{
          context.commit('realtime_endLoading');
          context.commit('realtime_tableData',response.data);
        })
        .catch((error)=> {
          console.log(error);
        });
    },
    realtime_cardData(context,{set}){
      api.getArpuCount(set)
        .then((response) =>{
          context.commit('realtime_cardData',response.data);
        })
        .catch((error)=> {
          console.log(error);
        });
    }
  }
}
